package com.aq.sales.business.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.aq.sales.business.intf.CommentBO;
import com.aq.sales.entity.Comment;
@Service
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class CommentBOImpl extends CommonBOImpl<Comment> implements CommentBO<Comment> {

		@Override
	public List<Comment> findAll(int accId) {
		Query qry=getCurrentSession().createQuery("from Comment where accId=:accId");
		qry.setInteger("accId", accId);
		return qry.list();
	}
	

	@Override
	public int insert(Comment obj) {
		getCurrentSession().save(obj);
		return 0;
	}

	@Override
	@Transactional
	public int update(Comment obj) {
		getCurrentSession().saveOrUpdate(obj);
		return 0;
	}

	@Override
	public int delete(Comment obj) {
		getCurrentSession().delete(obj);
		return 0;
	}


	@Override
	public Comment findById(int id) {
		throw new RuntimeException("This method is not Supported");
	}

	@Override
	public Comment findById(int id, int accId) {
		Query qry=getCurrentSession().createQuery("from Comment where id=:id AND accId=:accId");
		qry.setInteger("id", id);
		qry.setInteger("accId", accId);
		return (Comment)qry.uniqueResult();
	}


	@Override
	public List<Comment> query(String clause, int accId) {
		throw new RuntimeException("This method is not Supported");
	}
}
